package com.shiyang.factory.factorymethod.pizzastore.order;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.shiyang.factory.factorymethod.pizzastore.pizza.Pizza;

/**
 * @author shiyang date: 2020/9/8
 */
public abstract class OrderPizza {

    public OrderPizza() {
        Pizza pizza = null;
        String orderType = ""; // 订购pizza类型

        do {
            orderType = getType();
            pizza = createPizza(orderType);

            // 输出pizza 订购成功
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购失败");
                break;
            }
        } while (true);
    }

    // 定义一个抽象方法 让各个工厂子类自己实现
    abstract Pizza createPizza(String orderType);

    // 写一个方法 可以获取客户端希望订购的披萨种类
    private String getType() {
        try {
            InputStream in;
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type: ");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return "";
    }
}
